﻿create function [dbo].[fc_T_LayCTPhieu]
(
	@id_DPNX int
)
returns table
as
	return(
		select				vt.VatTu,
							t.MaKyHieu,
							dv.DVT,							                 
							t.Gia,
							p.SLKH,
							p.ThanhTien,
							n.KH_NguonVatTu,
							hd.SoHopDong ,
							t.SoTheKho,
							t.TangKeKhoang, 
							p.GhiChu
	from tblSLNX p inner join tblTon t on p.ID_MatHang = t.ID_MatHang
	inner join tblVatTu vt on t.ID_VatTu = vt.ID_VatTu
	inner join tblDVT dv on vt.ID_DVT = dv.ID_DVT
	left join tblNguonVatTu n on t.ID_NguonVatTu = n.ID_NguonVatTu
	left join tblHopDong hd on hd.ID_HopDong = t.ID_HopDong
	where p.ID_DPNX = @id_DPNX
	)
GO